<template>
    <div class="">
    <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 媒体资讯列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-button type="primary" round @click="urlAdd"><i class="el-icon-plus"> </i>&nbsp;&nbsp;发布资讯</el-button>
            <div style="height:40px"></div>
                <el-form :inline="true"  class="demo-form-inline">
                    <el-form-item label="媒体名称:">
                        <el-input v-model="categoryName" placeholder="请输入媒体名称" clearable style="width:200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="资讯标题:">
                        <el-input v-model="title" placeholder="请输入资讯标题" clearable style="width:200px;"></el-input>
                    </el-form-item>
                    
                    开始日期：
                    <el-date-picker value-format="yyyy-MM-dd" v-model="beginDate" type="date" class="handle-date"
                                    placeholder="选择开始日期"></el-date-picker>
                    结束日期：
                    <el-date-picker value-format="yyyy-MM-dd" v-model="endDate" type="date" class="handle-date"
                                    placeholder="选择结束日期"></el-date-picker>
                    <el-form-item>
                        <el-button type="primary" @click="onSelect"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                       
                    </el-form-item>
                </el-form>
                <el-table :data="tableData"  style="width: 100%"   ref="multipleTable">
                    <el-table-column prop="id" label="ID" width="100" align="center">
                    </el-table-column>
                    <el-table-column prop="college_name" label="媒体名称" width="200" align="center">
                    </el-table-column>
                    <el-table-column label="资讯封面图" width="140" align="center">
                        <template slot-scope="scope" >
                            <div><img :src="scope.row.head_img" style="width:100px;height:60px"></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="资讯标题"  align="center">
                    </el-table-column>
                    <el-table-column prop="authorize" label="类型" width="150" align="center">
                    </el-table-column>
                    <el-table-column prop="create_date" label="发布时间" width="150" align="center">
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="160">
                        <template slot-scope="scope" >
                            <el-button  size="small" type="text" @click="handleSelect(scope.$index, scope.row)">查看</el-button>
                            <el-button class="edit" size="small" type="text" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button class="del" size="small" type="text"  @click="handleDelete(scope.$index, scope.row)" >删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination" v-show="totalPages>1">
                    <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                    </el-pagination>
                </div>
                
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
        <!-- / 删除提示框 -->
    </div>
</template>
<script>
import {getMediaNewsList,postDeleteMediaNews} from '@/api/school'
export default {
    name:"medianewslist",
    data() {
        return {
        	type:'',//媒体类型：1新闻、2评析、3访谈、4技术、5全媒体
        	categoryId:'',//媒体单位ID
        	categoryName:'',//媒体单位名称
        	beginDate:'',//开始日期
        	endDate:'',//结束日期
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalElements:1,//默认总条数
            totalPages:1,//默认总页数
            tableData:[],//表格数据
            delIndex:0, //当前选中的下标
            delId:0,  //当前要删除的Id
            delVisible:false, //默认dialog 不弹出
            title:'',//媒体标题
            options: [{  //分类下拉框
	          value: ' ',
	          label: '全部'
	        },{  //分类下拉框
	          value: '1',
	          label: '新闻'
	        }, {
	          value: '2',
	          label: '评析'
	        }, {
	          value: '3',
	          label: '访谈'
	        }, {
	          value: '4',
	          label: '技术'
	        }, {
	          value: '5',
	          label: '全媒体'
	        }],
	        value:"",//下拉框
	        }
    },
    //实例创建
    created(){
        //
        this.getList();
    },
    //计算属性
    computed:{

    },
    //方法
    methods: {
    	//下拉框改变
    	typechoose(e){
    		this.type = e;
    	},
        //获取媒体列表
        getList(){
        	var param = {
        		type:this.type,
        		title:this.title,
        		categoryId:this.categoryId,
        		categoryName:this.categoryName,
        		beginDate:this.beginDate,
        		endDate:this.endDate,
        		pageIndex:this.pageIndex,
        		pageSize:this.pageSize
        	}
       		 getMediaNewsList(param).then((response) => {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
                    this.tableData = data.list;//列表数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total/this.pageSize);//总页数
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
        	})
        },
        //新增媒体路由
        urlAdd(){
            this.$router.push({ path:'/media/newslist/add'})
        },
        //查询
        onSelect(){
            this.pageIndex =1;
            this.getList();
        },
        //分页
        handleCurrentChange(val){
            this.pageIndex =val;
            this.getList();
        },
        //查看
        handleSelect(index,row){
            if(row.id && row.id>0){
                //跳转到商品编辑
                this.$router.push({ path: '/media/newslist/watch',query:{id:row.id}});
            }
        },
        //编辑
        handleEdit(index,row){
            if(row.id && row.id>0){
                //跳转到商品编辑
                this.$router.push({ path: '/media/newslist/edit',query:{id:row.id}});
            }
        },
        //删除
        handleDelete(index,row){
            // console.log(index,row.id);
            if(row.id && row.id>0){
                this.delIndex =index;//要删除的下标
                this.delId = row.id; //要删除的ID
                this.delVisible = true; //显示兑换弹出框
                 //console.log(this.delVisible);
            }else{
                // console.log("没触发");
            }
        },
        // 确定删除
        deleteRow(){
            //console.log(this.delId)
            if(this.delId>0){
                // console.log(this.delId)
                postDeleteMediaNews(this.delId).then(response=>{
                    // console.log(response);
                    if(response.code==200){
                        this.tableData.splice(this.delIndex, 1);
                        this.$message.success('删除成功');
                        this.delVisible = false;
                    }else{
                        this.$notify.error({
                            title: '删除失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                })
            }
            
        }
        
    }
}
</script>
<style lang="stylus" scoped>
	.edit{
	    color #ff9800;
	}
	.del{
	    color #e51c23;
	}
	.download{
	    color #67C23A;
	}
</style>


